import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class _3无重复字符的最长子串{
    public static int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int r =0;
        int left =0;
        for (int right = 0; right < s.length(); right++) {
            char c = s.charAt(right);
            while (set.contains(c)) {
                set.remove(s.charAt(left));
                left++;
            }
            set.add(c);
            r =Math.max(r, right-left +1);
        }
        return r;
    }

    public static void main(String[] args) {
        System.out.println();
        // System.out.println(lengthOfLongestSubstring("abcabcbb"));
        // System.out.println(lengthOfLongestSubstring("bbbbb"));
        // System.out.println(lengthOfLongestSubstring("pwwkew"));
        // System.out.println(lengthOfLongestSubstring(" "));
        // System.out.println(lengthOfLongestSubstring("au"));
        System.out.println(lengthOfLongestSubstring("dvdf"));
    }
}